/**
 * Copyright (c) 2014, 2017, Oracle and/or its affiliates.
 * The Universal Permissive License (UPL), Version 1.0
 */
"use strict";
/*
 Copyright 2013 jQuery Foundation and other contributors
 Released under the MIT license.
 http://jquery.org/license
*/
define(["ojs/ojcore","jquery","ojs/ojeditablevalue","ojs/ojbutton"],function(a,g){(function(){a.Ra("oj.ojInputNumber",g.oj.editableValue,{version:"1.0.0",defaultElement:"\x3cinput\x3e",widgetEventPrefix:"oj",options:{converter:a.za.dj(a.Hi.CONVERTER_TYPE_NUMBER).createConverter(),max:null,min:null,placeholder:void 0,rawValue:void 0,readOnly:!1,step:1,value:null},getNodeBySubId:function(a){var c=this._superApply(arguments),d;c||(d=a.subId,"oj-inputnumber-up"===d&&(c=this.widget().find(".oj-inputnumber-up")[0]),
"oj-inputnumber-down"===d&&(c=this.widget().find(".oj-inputnumber-down")[0]),"oj-inputnumber-input"===d&&(c=this.widget().find(".oj-inputnumber-input")[0]));return c||null},getSubIdByNode:function(a){var c=null;null!=a&&(a===this.widget().find(".oj-inputnumber-up")[0]?c={subId:"oj-inputnumber-up"}:a===this.widget().find(".oj-inputnumber-down")[0]?c={subId:"oj-inputnumber-down"}:a===this.widget().find(".oj-inputnumber-input")[0]&&(c={subId:"oj-inputnumber-input"}));return c||this._superApply(arguments)},
refresh:function(){this._super();this.ab()},stepDown:function(a){this.Rda(a,!1)},stepUp:function(a){this.Rda(a,!0)},widget:function(){return this.Am},Yf:function(b,c){var d=this.options,e=this;this._superApply(arguments);a.Fe.Cp([{ha:"disabled",Sd:!0},{ha:"placeholder"},{ha:"value"},{ha:"readonly",option:"readOnly",Sd:!0},{ha:"required",wh:!0,Sd:!0},{ha:"title"},{ha:"min"},{ha:"max"},{ha:"step"}],c,this,function(a){for(var b=["value","step","min","max"],c=0;c<b.length;c++){var g=b[c],m=g in a?a[g]:
d[g];null!=m&&(a[g]="step"===g?e.iE(m):e.Yo(g,m))}});if(void 0===d.value)throw Error("ojInputNumber has no value");if(null!=d.min&&null!=d.max&&d.max<d.min)throw Error("ojInputNumber's max must not be less than min");},_ComponentCreate:function(){this._super();this.TC();this.y$={};this.ab();this._on(this.xq);this._focusable(this.Am)},A1:function(a,c,d){this._superApply(arguments);switch(a){case "min":case "max":this.Ij(a,this.options[a])}},_setOption:function(a,c,d){var e;e="value"===a||"max"===a||
"min"===a?this.Yo(a,c):"step"===a?this.iE(c):c;this._super(a,e,d);if("max"===a||"min"===a)this.X5(),this.Px();"disabled"===a&&this.element.prop("disabled",!!c);"readOnly"===a&&(this.element.prop("readonly",!!c),this.bL("readOnly",this.options.readOnly),this.Mba("readOnly",this.options.readOnly))},_destroy:function(){var b=this._super();this.kM.ojButtonset("destroy");this.kM.remove();this.kM=this.xM=this.zO=null;a.D.unwrap(this.element,this.Am);clearTimeout(this.Te);return b},Ij:function(a,c,d){this._superApply(arguments);
var e="value"===a||"max"===a||"min"===a,f=e||"disabled"===a,g;f&&(g=this.qJ());e&&this.$K(g);"converter"===a&&this.Gba(g);f&&this.RL(g)},oc:function(){return this.options.converter?this._superApply(arguments):g.oj.ojInputNumber.prototype.options.converter},WB:function(){var a=this._superApply(arguments);null==this.options.min&&null==this.options.max||this.X5();return g.extend(this.y$,a)},_GetDefaultStyleClass:function(){return"oj-inputnumber"},xq:{input:function(a){this.jq(this.element.val(),a)},
keydown:function(a){a.keyCode===g.ui.keyCode.ENTER?(this.C4(a),a.preventDefault()):this.ak()&&this.Tv(a)&&a.preventDefault()},keyup:function(a){this.rw(a)},blur:function(a){this.C4(a)},"touchstart .oj-inputnumber-button":function(a){this.ak();this.Fz(null,g(a.currentTarget).hasClass("oj-inputnumber-up")?1:-1,a)},"touchend .oj-inputnumber-button":function(a){this.rw(a)},"touchcancel .oj-inputnumber-button":function(a){this.rw(a)},"mousedown .oj-inputnumber-button":function(a){this.Qv(a)&&(this.ak(),
this.Fz(null,g(a.currentTarget).hasClass("oj-inputnumber-up")?1:-1,a))},"mouseup .oj-inputnumber-button":function(a){this.Qv(a)&&this.rw(a)},"mouseenter .oj-inputnumber-button":function(a){g(a.currentTarget).hasClass("oj-active")&&this.Qv(a)&&(this.ak(),this.Fz(null,g(a.currentTarget).hasClass("oj-inputnumber-up")?1:-1,a))},"mouseleave .oj-inputnumber-button":function(a){this.Qv(a)&&this.rw(a)}},Ja:{Toa:"tooltipDecrement",Uoa:"tooltipIncrement"},js:{readOnly:"oj-read-only"},ab:function(){var a=this.F(this.Ja.Uoa),
c=this.F(this.Ja.Toa),d=this.qJ();this.zO.ojButton({label:a});this.xM.ojButton({label:c});this.$K(d);this.RL(d);"boolean"===typeof this.options.readOnly&&this.element.prop("readonly",this.options.readOnly);this.bL("readOnly",this.options.readOnly);this.Mba("readOnly",this.options.readOnly)},kAa:function(){this.zO.attr("data-oj-internal",!0);this.xM.attr("data-oj-internal",!0);this.kM.attr("data-oj-internal",!0)},dsa:function(){var a=this.Am.find(".oj-inputnumber-up"),c=this.Am.find(".oj-inputnumber-down"),
d=a[0].parentNode;this.zO=a.ojButton({display:"icons",icons:{start:"oj-component-icon oj-inputnumber-up-icon"}});this.xM=c.ojButton({display:"icons",icons:{start:"oj-component-icon oj-inputnumber-down-icon"}});this.kM=g(d).ojButtonset({focusManagement:"none"});this.kAa()},TC:function(){var a=this.element;this.Am=a.addClass("oj-inputnumber-input").wrap("\x3cspan class\x3d'oj-inputnumber-wrapper'\x3e\x3c/span\x3e").parent().append("\x3cdiv class\x3d'oj-buttonset-width-auto'\x3e\x3cbutton type\x3d'button' class\x3d'oj-inputnumber-button oj-inputnumber-down'\x3e\x3c/button\x3e\x3cbutton type\x3d'button' class\x3d'oj-inputnumber-button oj-inputnumber-up'\x3e\x3c/button\x3e\x3c/div\x3e");
this.oe?(this.Am=g(this.oe).append(this.Am),this.Am.addClass("oj-inputnumber oj-component")):this.Am=this.Am.wrap("\x3cdiv class\x3d'oj-inputnumber oj-component'\x3e\x3c/div\x3e").parent();this.saveType=a.prop("type");a.attr("type","text");this.Am.find(".oj-inputnumber-button").attr("tabIndex","-1");this.dsa()},Tv:function(a){var c=g.ui.keyCode;switch(a.keyCode){case c.UP:return this.Fz(null,1,a),!0;case c.DOWN:return this.Fz(null,-1,a),!0}return!1},wNa:function(){return"\x3cspan class\x3d'oj-inputnumber-wrapper'\x3e\x3c/span\x3e"},
MMa:function(){return"\x3cdiv class\x3d'oj-buttonset-width-auto'\x3e\x3cbutton type\x3d'button' class\x3d'oj-inputnumber-button oj-inputnumber-down'\x3e\x3c/button\x3e\x3cbutton type\x3d'button' class\x3d'oj-inputnumber-button oj-inputnumber-up'\x3e\x3c/button\x3e\x3c/div\x3e"},ak:function(){return this.ika=!0},Fz:function(a,c,d){a=a||500;clearTimeout(this.Te);this.Te=this._delay(function(){this.Fz(40,c,d)},a);this.YW(c*this.options.step,d)},YW:function(a,c){var d=this.qJ(),e=this.options,f=e.min,
g=e.max,e=e.step,k=this.oBa(f,e),d=this.l4(d,a,f,g,e,k);this.Nu()&&(this.element.val(d),this.$K(d),this.RL(d),this.jq(d,c));this.wc(d,c,this.iC.ema)},oBa:function(a,c){var d=this.lba(c);null!=a&&(d=Math.max(d,this.lba(a)));return d},lba:function(a){a=a.toString();var c=a.indexOf(".");return-1===c?0:a.length-c-1},l4:function(b,c,d,e,f,g){var k,l;if(0<g)return this.Opa(b,c,d,e,f,g);k=null!=d?d:0;try{b=parseFloat(b.toFixed(g))}catch(m){m instanceof TypeError&&(a.t.warn("inputNumber's value after conversion is not a number. \n\r\n                      The converter must convert the value to a Number. coercing using +"),
b=+b)}l=b-k;var r=Math.round(l/f)*f,r=parseFloat(r.toFixed(g));r!==l?(l=0>c?Math.ceil(l/f)*f:Math.floor(l/f)*f,b=k+l+c):b+=c;b=parseFloat(b.toFixed(g));return null!=d&&b<d?d:null!=e&&b>e?(d=Math.floor((e-k)/f)*f+k,d=parseFloat(d.toFixed(g))):b},Opa:function(b,c,d,e,f,g){a.p.assert(0<g);g=Math.pow(10,g);return this.l4(b*g,c*g,null!=d?d*g:d,null!=e?e*g:e,null!=f?f*g:f,0)/g},rw:function(){this.ika&&(clearTimeout(this.Te),this.ika=!1)},Qv:function(){return!a.D.yja()},RL:function(a){var c=this.options,
d=c.max,e=c.min,f=this.xM,g=this.zO,k,l;this.Am&&(f||g)&&(k=f.ojButton("option","disabled"),l=g.ojButton("option","disabled"),c.disabled||void 0===a?(k||f.ojButton("disable"),l||g.ojButton("disable")):null!=d&&a>=d?(k&&f.ojButton("enable"),l||g.ojButton("disable")):(null!=e&&a<=e?k||f.ojButton("disable"):k&&f.ojButton("enable"),l&&g.ojButton("enable")))},qJ:function(){var a,c;try{c=this.Si()||0,a=this.RK(c)}catch(d){a=void 0}return a},C4:function(a){var c=this.element.val(),d;this.rw();d=this.qJ();
this.$K(d);this.RL(d);this.wc(c,a)},X5:function(){var b=this.options,c=b.min,d=b.max,e=(b=b.translations)?b.numberRange||{}:{},f,g,k,l,m,r,t,b=e.hint||{},s=e.messageDetail||{},e=e.messageSummary||{};null!==b&&(f=b.min||null,g=b.max||null,k=b.inRange||null);null!==s&&(l=s.rangeOverflow||null,m=s.rangeUnderflow||null);null!==e&&(r=e.rangeOverflow||null,t=e.rangeUnderflow||null);c={min:null!=c?c:void 0,max:null!=d?d:void 0,hint:{min:f||null,max:g||null,inRange:k||null},messageDetail:{rangeOverflow:l||
null,rangeUnderflow:m||null},messageSummary:{rangeOverflow:r||null,rangeUnderflow:t||null},converter:this.oc()};this.y$[a.Ve.VALIDATOR_TYPE_NUMBERRANGE]=a.za.sx(a.Ve.VALIDATOR_TYPE_NUMBERRANGE).createValidator(c)},Yo:function(a,c){var d;d=null!==c?+c:c;if(isNaN(d))throw Error("ojInputNumber's "+a+" option is not a number");return d},iE:function(a){if(null===a)return 1;a=this.Yo("step",a);if(0>=a)throw Error("Invalid step for ojInputNumber; step must be \x3e 0");if(null===a||0>=a)a=1;return a},bL:function(a,
c){-1!=Object.keys(this.js).indexOf(a)&&this.widget().toggleClass(this.js[a],!!c)},Mba:function(a,c){c?this.element.removeAttr("role"):this.element.attr("role","spinbutton")},$K:function(a){this.element.attr({"aria-valuemin":this.options.min,"aria-valuemax":this.options.max,"aria-valuenow":a});this.Gba(a)},Gba:function(a){var c=this.element,d=c.val();this.TB("value",""+a,d)||c.attr({"aria-valuetext":d})},Rda:function(a,c){this.ak();c?this.YW((a||1)*this.options.step):this.YW((a||1)*-this.options.step);
this.rw()}})})();a.Components.Xa("ojInputNumber","editableValue",{properties:{converter:{type:"Object"},max:{type:"number"},min:{type:"number"},placeholder:{type:"string"},rawValue:{type:"string",writeback:!0,readOnly:!0},readOnly:{type:"boolean"},step:{type:"number"},value:{type:"number",writeback:!0}},methods:{destroy:{},refresh:{},stepDown:{},stepUp:{},widget:{}},extension:{_hasWrapper:!0,_innerElement:"input",_widgetName:"ojInputNumber"}});a.Components.register("oj-input-number",a.Components.getMetadata("ojInputNumber"))});